const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
const util = require('../../utils/util.js');
Page({
  data: {
    isfixed:false,
    listsheight:20,
    cate:'联结',
    iscate:false,
    categoryList:[],
    productList:[]

  },
  onLoad(options) {
    let _this = this
    let cate = options.cate,
    typeid = options.typeid
    console.log(typeid)
    console.log(cate)
    wx.setNavigationBarTitle({
      title:cate
    })
    Controller.case({
      "apiList": `ekey=1&page=1`,
      "typeid": typeid
    }).then(res => {
      let productList = res.data.apiList[1]
      _this.setData({
        cate,
        productList
      });
      console.log(productList)
    }).catch(res=>{
  
    })
    
  },
  onShow(){
 
  },
  selectcate(e){
    this.setData({
      cate:e.currentTarget.dataset.name,
      index:e.currentTarget.dataset.index,
      iscate:false,
    })
  },
  opencate(){
    this.setData({
      iscate:!this.data.iscate,
    })
  },
  closecate(){
    this.setData({
      cate:'',
      iscate:false,
    })
  },
  onPageScroll(event) {

    let scrollTop = event.scrollTop //页面滚动
    if (scrollTop >= this.data.listsheight) { //页面向上滚动indexKey
      this.setData({
        isfixed:true
      })
    } else { //页面向下滚动
      this.setData({
        isfixed:false
      })
    }
  },
  onShareAppMessage: function (e) {
    
  },
  onShareTimeline: function(res){
    
  },
  /**
   * 跳转列表页
   */
  jumpList(e) {
    util.jumpList(e)
  },

    /**
   * 跳转列表页
   */
  jumpView(e) {
    util.jumpList(e)
  },
  collectBtn(e){
    Controller.collect({
      "aid": e.currentTarget.dataset.id,
    }).then(res => {
      console.log(res.data)
      let categoryList = res.data.apiChannel[1]
      _this.setData({
        categoryList,
        productList
      });
      console.log(productList)
    }).catch(res=>{
  
    })
  },
  goto(e){
    let url = e.currentTarget.dataset.url
    console.log(e.currentTarget.dataset)
    wx.navigateTo({
      url: `/pages/webview/webview?url=${url}`,
    })
  }
})